home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / Asm / Demos / BigBobs.s < prev    next >
Encoding:
Text File  |  1997-12-16  |  9.6 KB  |  426 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Name:      Big Bouncing Bobs
  3. ;Author:    Paul Manias
  4. ;Copyright: DreamWorld Productions (c) 1996-1997.  Freely distributable.
  5.  
  6.     INCDIR    "INCLUDES:"
  7.     INCLUDE    "dpkernel/dpkernel.i"
  8.  
  9. MAX_IMAGES =    20
  10.  
  11.     SECTION    "Demo",CODE
  12.  
  13. ;===========================================================================;
  14. ;                             INITIALISE DEMO
  15. ;===========================================================================;
  16.  
  17.     STARTDPK
  18.  
  19. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  20.     move.l    DPKBase(pc),a6    ;Load bob picture.
  21.     lea    PIC_BobTags(pc),a0
  22.     CALL    Init
  23.     tst.l    d0
  24.     beq    .Exit
  25.  
  26.     move.l    PIC_Bobs(pc),a1
  27.     move.l    a1,BallPic
  28.     move.l    a1,LacedPic
  29.  
  30.     move.l    PIC_Palette(a1),GSPalette
  31.     move.l    PIC_Bitmap(a1),a2
  32.     move.l    BMP_AmtColours(a2),GSColours
  33.  
  34.     moveq    #ID_RASTER,d0    ;Get raster object.
  35.     CALL    Get
  36.     move.l    d0,Raster
  37.     beq.s    .Exit
  38.  
  39.     move.l    Raster(pc),a0    ;a0 = Raster
  40.     lea    RastCList(pc),a1    ;a1 = Colourlist
  41.     move.l    a1,RAS_Command(a0)    ;a0 = Raster->Command = Colourlist;
  42.     move.l    a0,RSH_Prev(a1)    ;a1 = Colourlist->Prev = Raster;
  43.  
  44.     lea    ScreenTags(pc),a0    ;Initialise screen.
  45.     sub.l    a1,a1
  46.     CALL    Init
  47.     tst.l    d0
  48.     beq.s    .Exit
  49.  
  50. ;--------------------------------------------------------------------------;
  51. ;Initialise restore and bob objects.
  52.  
  53.     lea    RestoreTags(pc),a0    ;a0 = Restore tags.
  54.     move.l    Screen(pc),a1    ;a1 = Screen.
  55.     CALL    Init    ;>> = Initialise the restore.
  56.     tst.l    d0    ;d0 = Check for errors.
  57.     beq.s    .Exit    ;>> = Error, exit.
  58.  
  59.     lea    TAGS_Ball(pc),a0    ;Initialise the Ball mbob.
  60.     move.l    Screen(pc),a1
  61.     CALL    Init
  62.     tst.l    d0
  63.     beq.s    .Exit
  64.  
  65.     lea    TAGS_Interlaced(pc),a0    ;Initialise "HiRes Interlaced" bob.
  66.     move.l    Screen(pc),a1
  67.     CALL    Init
  68.     tst.l    d0
  69.     beq.s    .Exit
  70.  
  71. ;--------------------------------------------------------------------------;
  72. ;Initialise joydata object.
  73.  
  74.     moveq    #ID_JOYDATA,d0    ;Get joydata structure for reading
  75.     CALL    Get    ;port 0.
  76.     move.l    d0,JoyData
  77.     beq.s    .Exit
  78.     move.l    d0,a0    ;Initialise the joydata structure.
  79.     sub.l    a1,a1
  80.     CALL    Init
  81.     tst.l    d0
  82.     beq.s    .Exit
  83.  
  84.     move.l    Screen(pc),a0
  85.     CALL    Display
  86.  
  87.     bsr.s    Main
  88.  
  89. .Exit    move.l    DPKBase(pc),a6
  90.     move.l    JoyData(pc),a0
  91.     CALL    Free
  92.     move.l    BOB_Interlaced(pc),a0
  93.     CALL    Free
  94.     move.l    MBOB_Ball(pc),a0
  95.     CALL    Free
  96.     move.l    Raster(pc),a0
  97.     CALL    Free
  98.     move.l    Restore(pc),a0
  99.     CALL    Free
  100.     move.l    Screen(pc),a0
  101.     CALL    Free
  102.     move.l    PIC_Bobs(pc),a0
  103.     CALL    Free
  104.     move.l    Raster(pc),a0
  105.     CALL    Free
  106.     MOVEM.L    (SP)+,A0-A6/D1-D7
  107.     moveq    #ERR_OK,d0
  108.     rts
  109.  
  110. ;===========================================================================;
  111. ;                                DEMO CODE
  112. ;===========================================================================;
  113.  
  114. Main:    move.l    Screen(pc),a2    ;a2 = Screen.
  115.     move.l    GS_Bitmap(a2),a3    ;a3 = Bitmap.
  116.  
  117.     move.l    BOB_Interlaced(pc),a1    ;a1 = Bob to draw.
  118.     move.w    GS_Width(a2),d0
  119.     sub.w    BOB_Width(a1),d0
  120.     move.w    d0,BOB_XCoord(a1)
  121.  
  122.     move.l    DPKBase(pc),a6    ;a6 = DPKBase.
  123.     move.l    GS_MemPtr2(a2),BMP_Data(a3)
  124.     move.l    BOB_Interlaced(pc),a0    ;a0 = Bob to draw.
  125.     CALL    Draw    ;>> = Draw the Bob
  126.  
  127.     move.l    GS_MemPtr1(a2),BMP_Data(a3)
  128.     move.l    BOB_Interlaced(pc),a0    ;a0 = Bob to draw.
  129.     CALL    Draw    ;>> = Draw the Bob
  130.  
  131.     moveq    #$00,d7
  132.     move.l    MBOB_Ball(pc),a1
  133.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  134.     move.w    MB_AmtEntries(a1),d2    ;a2 = Amount of entries.
  135.     subq.w    #1,d2    ;d2 = --1 for loop.
  136.     moveq    #$00,d3
  137.  
  138. .create    eor.w    #1,d3
  139.     moveq    #8,d1    ;Set Y speed here.
  140.     CALL    FastRandom
  141.     addq.w    #2,d0
  142.     move.w    d0,BE_YSpeed(a2)
  143.     move.w    #8,d1    ;Set X speed here.
  144.     CALL    FastRandom
  145.     addq.w    #1,d0
  146.     move.w    d0,BE_XSpeed(a2)
  147.     tst.w    d3
  148.     beq.s    .posx
  149.     neg.w    BE_XSpeed(a2)
  150.  
  151. .posx    move.l    Screen(pc),a0
  152.     move.w    GS_Height(a0),d1    ;Starting Y coordinate.
  153.     asr.w    #1,d1
  154.     CALL    FastRandom
  155.     asr.w    #1,d1
  156.     add.w    d1,d0
  157.     move.w    d0,BE_YCoord(a2)
  158.  
  159.     move.w    GS_Width(a0),d1    ;Starting X coordinate.
  160.     CALL    FastRandom
  161.     move.w    d0,BE_XCoord(a2)
  162.  
  163.     moveq    #12,d1
  164.     CALL    FastRandom
  165.     move.w    d0,BE_Frame(a2)
  166.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  167.     move.w    #1,BE_FChange(a2)
  168.     move.w    d3,BE_Locked(a2)
  169.  
  170.     lea    NBE_SIZEOF(a2),a2
  171.     dbra    d2,.create
  172.     bra.s    Loop
  173.  
  174. .Sets    dc.b    0,0,0,0
  175.     dc.b    1,1,1,1
  176.     dc.b    2,2,2,2
  177.  
  178. ;---------------------------------------------------------------------------;
  179.  
  180. Loop:    move.l    Screen(pc),a0    ;a0 = Screen.
  181.     move.l    MBOB_Ball(pc),a1
  182.     addq.w    #1,d7
  183.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  184.     move.w    MB_AmtEntries(a1),d2
  185.     subq.w    #1,d2
  186. .update    bsr.s    UpdateBob
  187.     lea    NBE_SIZEOF(a2),a2
  188.     dbra    d2,.update
  189.  
  190.     move.l    DPKBase(pc),a6
  191.     move.l    Restore(pc),a0
  192.     CALL    Activate
  193.  
  194.     move.l    MBOB_Ball(pc),a0    ;a0 = Bob to draw.
  195.     CALL    Draw    ;>> = Draw the Bob.
  196.  
  197.     move.l    SCRBase(pc),a6
  198.     CALL    scrWaitAVBL
  199.  
  200.     move.l    Screen(pc),a0
  201.     CALL    scrSwapBuffers
  202.  
  203.     move.l    DPKBase(pc),a6
  204.     move.l    JoyData(pc),a0
  205.     CALL    Query
  206.     move.l    JoyData(pc),a0
  207.     move.l    JD_Buttons(a0),d0
  208.     btst    #JB_LMB,d0
  209.     beq.s    Loop
  210.     rts
  211.  
  212. ;===========================================================================;
  213. ;                               UPDATE A BOB
  214. ;===========================================================================;
  215. ;Function: Moves the entity according to its internal settings.
  216. ;Requires: a1 = Bob structure.
  217. ;       a2 = Entry to update.
  218.  
  219. GRAVITY =    1
  220.  
  221. UpdateBob:
  222.     move.l    MB_Screen(a1),a0    ;a0 = Bitmap
  223.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  224.     add.w    BE_YSpeed(a2),d0    ;d0 = (YCoord)+YSpeed
  225.     cmp.w    GS_Height(a0),d0    ;d0 = Should this bob bounce?
  226.     blt.s    .NoBounce    ;>> = No.
  227.     neg.w    BE_YSpeed(a2)    ;a2 = Bounce the bob!
  228.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  229.     bra.s    .CheckX
  230. .NoBounce
  231.     move.w    d0,BE_YCoord(a2)    ;d0 = Save the change.
  232.     addq.w    #GRAVITY,BE_YSpeed(a2)    ;a2 = Gravity pushes the bob down.
  233.  
  234. .CheckX    move.w    BE_XCoord(a2),d0
  235.     add.w    BE_XSpeed(a2),d0
  236.     cmp.w    GS_Width(a0),d0
  237.     bcs.s    .NoXBounce
  238.     neg.w    BE_XSpeed(a2)
  239.     bra.s    .Animate
  240. .NoXBounce
  241.     move.w    d0,BE_XCoord(a2)
  242.  
  243. ;---------------------------------------------------------------------------;
  244.  
  245. .Animate
  246.     tst.w    BE_Locked(a2)
  247.     beq.s    .exit
  248.     move.w    d7,d6
  249.     and.w    #%00000011,d6
  250.     bne.s    .exit
  251.     move.w    BE_FChange(a2),d1
  252.     bgt.s    .Positive
  253.  
  254. .Negative
  255.     cmp.w    #1,BE_Set(a2)
  256.     bgt.s    .NBlue
  257.     beq.s    .NGreen
  258. .NRed    add.w    d1,BE_Frame(a2)
  259.     tst    BE_Frame(a2)
  260.     bge.s    .exit
  261.     move.w    #1,BE_FChange(a2)
  262.     clr.w    BE_Frame(a2)
  263.     rts
  264.  
  265. .NGreen    add.w    d1,BE_Frame(a2)
  266.     cmp.w    #4,BE_Frame(a2)
  267.     bge.s    .done
  268.     move.w    #1,BE_FChange(a2)
  269.     move.w    #4,BE_Frame(a2)
  270.     rts
  271.  
  272. .NBlue    add.w    d1,BE_Frame(a2)
  273.     cmp.w    #8,BE_Frame(a2)
  274.     bge.s    .done
  275.     move.w    #1,BE_FChange(a2)
  276.     move.w    #8,BE_Frame(a2)
  277. .exit    rts
  278.  
  279. .Positive
  280.     cmp.w    #1,BE_Set(a2)
  281.     bgt.s    .PBlue
  282.     beq.s    .PGreen
  283. .PRed    add.w    d1,BE_Frame(a2)
  284.     cmp.w    #3,BE_Frame(a2)
  285.     ble.s    .done
  286.     move.w    #-1,BE_FChange(a2)
  287.     move.w    #2,BE_Frame(a2)
  288.     rts
  289.  
  290. .PGreen    add.w    d1,BE_Frame(a2)
  291.     cmp.w    #7,BE_Frame(a2)
  292.     ble.s    .done
  293.     move.w    #-1,BE_FChange(a2)
  294.     move.w    #6,BE_Frame(a2)
  295.     rts
  296.  
  297. .PBlue    add.w    d1,BE_Frame(a2)
  298.     cmp.w    #11,BE_Frame(a2)
  299.     ble.s    .done
  300.     move.w    #-1,BE_FChange(a2)
  301.     move.w    #10,BE_Frame(a2)
  302. .done    rts
  303.  
  304. ;===========================================================================;
  305. ;                                  DATA
  306. ;===========================================================================;
  307.  
  308.   STRUCTURE    NBE,BE_SIZEOF    ;Definition for the mutated Entry-
  309.     WORD    BE_XSpeed    ;list in the Ball bob.
  310.     WORD    BE_YSpeed
  311.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  312.     WORD    BE_FChange
  313.     WORD    BE_Locked
  314.     LABEL    NBE_SIZEOF
  315.  
  316. JoyData:    dc.l  0
  317.  
  318. ;---------------------------------------------------------------------------;
  319.  
  320. RestoreTags:    dc.l  TAGS_RESTORE
  321. Restore:    dc.l  0
  322.         dc.l  RSA_Entries,MAX_IMAGES
  323.         dc.l  TAGEND
  324.  
  325. ;---------------------------------------------------------------------------;
  326.  
  327. ScreenTags:    dc.l  TAGS_SCREEN
  328. Screen:        dc.l  0
  329.         dc.l  GSA_Raster
  330. Raster:        dc.l  0
  331.         dc.l  GSA_Width,640
  332.         dc.l  GSA_Height,512
  333.         dc.l  GSA_Attrib,DBLBUFFER
  334.         dc.l  GSA_ScrMode,HIRES|LACED
  335.         dc.l    GSA_BitmapTags,0
  336.         dc.l    BMA_AmtColours
  337. GSColours:    dc.l    0
  338.         dc.l    TAGEND,0
  339.         dc.l  GSA_Palette
  340. GSPalette:    dc.l  0
  341.         dc.l  TAGEND
  342.  
  343. RastCList:    dc.w  ID_RASTCOLOURLIST,1
  344.         dc.l  0,0,0
  345.         dc.w  300,30    ;YCoord, Skip
  346.         dc.l  0    ;Colour
  347.         dc.l  .colours    ;Values
  348.  
  349. .colours    dc.l  $100000,$200000,$300000,$400000,$500000,$600000,$700000
  350.         dc.l  -1
  351.  
  352. ;---------------------------------------------------------------------------;
  353.  
  354. PIC_BobTags:    dc.l  TAGS_PICTURE
  355. PIC_Bobs:    dc.l  0
  356.         dc.l  PCA_Options,IMG_RESIZE
  357.         dc.l  PCA_Source,.file
  358.         dc.l    PCA_BitmapTags,0
  359.         dc.l    BMA_Width,96*2
  360.         dc.l    BMA_Height,71*2
  361.         dc.l    BMA_MemType,MEM_VIDEO
  362.         dc.l    TAGEND,0
  363.         dc.l  TAGEND
  364.  
  365. .file        FILENAME "GMS:demos/data/PIC.HRPulse"
  366.  
  367. ;---------------------------------------------------------------------------;
  368.  
  369. TAGS_Ball:    dc.l  TAGS_MBOB
  370. MBOB_Ball:    dc.l  0
  371.         dc.l  MBA_AmtEntries,MAX_IMAGES
  372.         dc.l  MBA_GfxCoords,BallFrames
  373.         dc.l  MBA_Width,32
  374.         dc.l  MBA_Height,32
  375.         dc.l  MBA_EntryList,Images
  376.         dc.l  MBA_Attrib,BBF_GENMASKS|BBF_CLRNOMASK|BBF_CLEAR|BBF_CLIP
  377.         dc.l  MBA_Source
  378. BallPic:    dc.l  0
  379.         dc.l  MBA_EntrySize,NBE_SIZEOF
  380.         dc.l  TAGEND
  381.  
  382. BallFrames:    dc.w  00,32*0    ;RED
  383.         dc.w  00,32*1
  384.         dc.w  00,32*2
  385.         dc.w  00,32*3
  386.         dc.w  32,32*0    ;GREEN
  387.         dc.w  32,32*1
  388.         dc.w  32,32*2
  389.         dc.w  32,32*3
  390.         dc.w  64,32*0    ;BLUE
  391.         dc.w  64,32*1
  392.         dc.w  64,32*2
  393.         dc.w  64,32*3
  394.         dc.l  -1
  395.  
  396. ;---------------------------------------------------------------------------;
  397.  
  398. TAGS_Interlaced    dc.l  TAGS_BOB
  399. BOB_Interlaced:    dc.l  0
  400.         dc.l  BBA_GfxCoords,LacedFrames
  401.         dc.l  BBA_Width,96*2
  402.         dc.l  BBA_Height,7*2
  403.         dc.l  BBA_Attrib,BBF_GENMASKS|BBF_CLIP
  404.         dc.l  BBA_Source
  405. LacedPic:    dc.l  0
  406.         dc.l  TAGEND
  407.  
  408. LacedFrames:    dc.w  0,16*4*2    ;X/Y Graphic
  409.         dc.l  -1
  410.  
  411. ;---------------------------------------------------------------------------;
  412.  
  413.     SECTION    Images,BSS
  414.  
  415. Images    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  416.  
  417. ;===========================================================================;
  418.  
  419. ProgName:    dc.b  "Big Bouncing Bobs",0
  420. ProgAuthor:    dc.b  "Paul Manias",0
  421. ProgDate:    dc.b  "10 December 1997",0
  422. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1997.  Freely distributable.",0
  423. ProgShort:    dc.b  "Multiple bobs demo.",0
  424.         even
  425.  
  426.